class Solution {
    //表示数值的字符串遵循A[.[B]][e|EC],其中A不是必须的；A、C可以是带符号的整数
public:
    bool isNumber(string s) {
        if(s == "")  return false;

        int sptr = 0;//sptr为下标
        //吸空格:字符串前后可以有空格，中间不允许有空格
        while(s[sptr] != '\0' && s[sptr] == ' ')  ++sptr;

        bool judge = scanInt(s, sptr);

        if(s[sptr] == '.'){
            judge = scanUnsignedInt(s,++sptr) || judge;  //A、B至少需要有一个
        }

        if(s[sptr] == 'e' || s[sptr] == 'E'){
            judge = judge && scanInt(s, ++sptr); //e后面不允许为空
        }

        while(s[sptr] != '\0' && s[sptr] == ' ')  ++sptr;
        return judge && (s[sptr] == '\0');
    }

    bool scanUnsignedInt(string &s, int &sptr){
        int before = sptr;
        while(s[sptr] != '\0' && s[sptr] >= '0' && s[sptr] <= '9')  ++sptr;
        //若有数字，则sptr应该有增加
        return sptr > before;
    }

    bool scanInt(string &s, int &sptr){
        if(s[sptr] == '+' || s[sptr] == '-')  ++sptr;
        return scanUnsignedInt(s, sptr);
    }
};